package com.pet.server.ext.action.home;

import java.util.List;

import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.BeanToJson;
import com.pet.server.ext.Result;
import com.pet.server.ext.constants.BaseAttribute;
import com.pet.server.ext.data.Article;
import com.pet.server.ext.data.Campaign;
import com.pet.server.ext.data.Faxian;
import com.pet.server.ext.data.RequestInfo;
import com.pet.server.ext.service.ArticleService;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.HomeUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.cache.PetCache;
public class Index extends ActionBase{
	
	public Index(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		
	}
	
	@Override
	public Result invokeService() throws ApiError {
		JSONObject o = new JSONObject();
		Result result = new Result();
		UserService userService = new UserService();
        //banner
		List<Campaign> list = userService.queryForHome(BaseAttribute.pay_type.banner.toString(),6);
		o.put("banner", BeanToJson.listTojson(list,"id","seq","play_type"));
		
		//tuijian
		List<Campaign> tuijian = userService.queryForHome(BaseAttribute.pay_type.tuijian.toString(),1);
		o.put("tuijian", BeanToJson.listTojson(tuijian,"id","seq","play_type"));
		
		//tiwen
		List<RequestInfo> request = userService.queryRequestForHome(3);
		o.put("request", BeanToJson.listTojson(request));
		
		List<Article> article = PetCache.queryArticleForIndex(null, null, null);
		o.put("article", BeanToJson.listTojson(article,"text"));
		
		
		List<Faxian> faxian = PetCache.queryFaxian();
		o.put("faxian", BeanToJson.listTojson(faxian));
		
		
		//
		//article 
		//articleService.query
		result.put("data", o);

		return result;
	}


}
